[#include "single/layout/layout02/layout.ftl"/]
[@htmlHead]
<link href="${jpath}/assets/public/plugins/jqGrid/css/ui.jqgrid-bootstrap.css" rel="stylesheet" type="text/css"/>
<style TYPE="text/css">
    .form-horizontal .control-label{text-align:right;margin-bottom:0;padding-top:7px}}
</style>
[/@htmlHead]
[@htmlBody]
[#--<div class="row">--]
    [#--<form class="form-horizontal " id="search-form">--]
        [#--<div class="col-xs-12">--]
        [#--<div class="form-group ">--]

            [#--<label class=" col-xs-2 control-label">名称：</label>--]

            [#--<div class=" col-xs-2">--]
                [#--<input type="text" name="name" class="form-control ">--]
            [#--</div>--]


            [#--<label class=" col-xs-2 control-label">英文名称：</label>--]

            [#--<div class=" col-xs-2">--]
                [#--<input type="text" name="ename" class="form-control ">--]

            [#--</div>--]

            [#--<div class="col-xs-2">--]
                [#--<button class=" btn btn-info btn-sm" type="button" onclick="doSearch()"><i class="ice-icon fa fa-search"></i>查找--]
                [#--</button>--]
            [#--</div>--]
        [#--</div>--]
        [#--</div>--]
    [#--</form>--]

[#--</div>--]

<div class="row">
    <div class="col-xs-12" style="max-height: 430px;overflow-y: auto;overflow-x: hidden;">
        <input type="hidden" name="accountId" value="${accountId}"/>
        <table id="jqGrid" class="grid_auto" grid_ref=""></table>
    </div>
</div>

<div class="row navbar-fixed-bottom">
    <div class="col-xs-12 text-center">
        <input type="button" class="btn btn-info btn-sm" value="确定" onclick="doInfo()"/>
        <input type="button" class="btn btn-cancle  btn-sm" value="关闭" onclick="$.bootbox.hideAll()"/>
    </div>
</div>
[/@htmlBody]
[@htmlFoot]

<script type="text/javascript" src="${jpath}/assets/public/plugins/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="${jpath}/assets/public/plugins/jqGrid/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="${jpath}/assets/public/plugins/jqGrid/jqGrid-extends.js"></script>
<!--bootbox-->
<script src="${jpath}/assets/public/plugins/dialog/bootbox.js" type="text/javascript"></script>
<script type="text/javascript">
    var id = $("input[name=accountId]").val();
    $(document).ready(function () {
        $("#jqGrid").jqGrid({
            url: '${base}/app/view/accountAppCodeList?accountId='+id,
            datatype: "json",
            styleUI: 'Bootstrap',
            colNames: ['ID', '名称', '英文名称', '描述', '创建时间'],
            colModel: [
                {name: 'id', index: 'id',hidden:true, width: 10},
                {name: 'appName', index: 'appName', width: 100},
                {name: 'appNameCode', index: 'appNameCode', width: 100},
                {name: 'description', index: 'description', width: 120},
                {name: 'createTime', index: 'createTime', width: 200, formatter: tools.formatDate}
            ],
            height: 'auto',
            sortable: false,
            multiselect: true,
            shrinkToFit:false,
            autowidth:false,
            loadComplete: function (data) {
                if (typeof data != "undefined") {
                    var gid=this.id;
                    var rows = data;
                    var code = data.code;
                    if (code&&"ERROR" == code) {
                        $.messager.alert0({selector: "#indexAlert", type:code, html: data.message});
                        return;
                    }
                    if (!rows||rows == null || rows.length <= 0) {

                    } else {
                        for (var i in rows) {
                            if (rows[i].isCheck) {
                                $("#" + rows[i].id).find("input").trigger("click");
                            }
                        }
                    }
                }
            }
        })
    });

    function doInfo() {
        var ids = $('#jqGrid').getGridParam("selarrrow");//获得被选中行
        var name=[];
        for(var i in ids){
            name.push($("#"+ids[i]).find("td:eq(3)").html());//获得被选中行的name
        }
        var idField = tools.getQueryString('idField');
        var textField = tools.getQueryString('textField');
        var fn = tools.getQueryString('fn');
        if (typeof fn == 'function') {
            eval("top." + fn + "(" + code + "," + name + ")");
        } else {
            var contentFrame = tools.getCurrentFrame();
            if (contentFrame) {
                var contentFrameDoc = contentFrame.document;
                $("#" + idField, contentFrameDoc).val(ids.toString());
                $("#" + textField, contentFrameDoc).val(name.toString());
            } else {
                $("#" + idField, top.window.document).val(ids.toString());
                $("#" + textField, top.window.document).val(name.toString());
            }
            $.bootbox.hideAll();
        }
    }

    function doSearch(){
        var name=$("input[name=name]").val();
        var ename=$("input[name=ename]").val();
        if(!name||!ename){
            $("#jqGrid").jqGrid('setGridParam',{
                datatype:'json',
                postData:{'appName':name,'appNameCode':ename} //发送数据
            }).trigger("reloadGrid"); //重新载入
        }
    }
</script>
[/@htmlFoot]